import type { AstroIntegration } from "astro";
import injectCore from "./core";

export default function BuildServiceWorker(): AstroIntegration {
  return {
    name: "BuildServiceWorker",
    hooks: {
      // "astro:config:setup": ({ command, injectRoute, injectScript, config, }) => {
      //   injectScript("head-inline", `\
      //   if ('serviceWorker' in navigator) {
      //   navigator.serviceWorker.register('/${SW_NAME}');
      //   }`);
      // },
      // "": async (e) => { },
      "astro:build:done": async ({ pages, dir, logger }) => {
        await injectCore(dir, pages.map((p) => p.pathname), logger)
      },
    }
  }
}